import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    //快捷tab组件开始
    cacheRoute: [],
    //快捷tab组件结束
  },
  mutations: {
    //快捷tab组价开始
    ADD_CACHE_ROUTE(state, obj) {
      state.cacheRoute.map((item, index) => {
        if (obj.name && item.name == obj.name) {
          state.cacheRoute.splice(index, 1); // 去重
        }
      });
      state.cacheRoute.push(obj);
    },
    DELETE_CACHE_ROUTE(state, obj) {
      let index = state.cacheRoute.indexOf(obj);
      state = state.cacheRoute.splice(index, 1);
    },
    DELETE_CACHE_ROUTE_ALL(state) {
      state.cacheRoute = [];
    },
    //快捷tab组件结束
  },
  actions: {
    //快捷tab组价开始
    addCacheRoute({ commit }, obj) {
      commit("ADD_CACHE_ROUTE", obj);
    },
    deleteCacheRoute({ commit }, obj) {
      commit("DELETE_CACHE_ROUTE", obj);
    },
    deleteCacheRouteAll({ commit }) {
      commit("DELETE_CACHE_ROUTE_ALL");
    },
     //快捷tab组件结束
  },
  modules: {},
});
